package com.example.demo.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.exception.TestException;
import com.example.demo.result.R;
import com.example.demo.result.ResultCodeEnum;

/**
 * 测试控制器
 *
 * @author 爷爷的茶七里香
 * @date 2022/05/30
 */
@RestController
@RequestMapping("testR")
public class TestController {

    /**
     * @return {@link R}
     */
    @GetMapping("ok")
    public R testOk() {
        // 演示出现异常情况
        try {
            int a = 1 / 0;
        } catch (Exception e) {
            // 抛出自定义的异常
            throw new TestException(ResultCodeEnum.TEST_NUMBER);
        }
        Map<String, Object> data = new HashMap<>();
        data.put("name", "李太白");
        return R.ok().data(data);
    }
}
